import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/10 8:32
 * @description 二分查找
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] p = {30, 11, 23, 4, 20};
        System.out.println(solution.minEatingSpeed(p, 5));
    }
    public int minEatingSpeed(int[] piles, int h) {
        int l = 1, r = 0;
        for (int pile: piles) {
            if (pile > r) {
                r = pile;
            }
        }
        int ans = 0;
        while (l <= r) {
            int mid = (l + r) / 2;
            if(check(piles, mid, h)) {
                ans = mid;
                r  = mid - 1;
            }else {
                l = mid + 1;
            }
        }
        return ans;
    }
    public boolean check(int[] piles, int k, int h) {
        for (int p: piles) {
            h -= (p - 1) / k + 1;
            if (h < 0) {
                return false;
            }
        }
        return true;
    }
}
